package netcom;

import java.util.Calendar;

import utilities.Constants;

public class ServiceInstance {
	
	private String servIp;
	private int servPort;
	private String servName;
	private int lastMessageId;
	private long lastMessageTime = 0;
	
	/**
	 * Getter / Setters
	 */
	public synchronized String getServIp() {
		return servIp;
	}
	public synchronized void setServIp(String servIp) {
		this.servIp = servIp;
	}
	public synchronized int getServPort() {
		return servPort;
	}
	public synchronized void setServPort(int servPort) {
		this.servPort = servPort;
	}
	public synchronized String getServName() {
		return servName;
	}
	public synchronized void setServName(String servName) {
		this.servName = servName;
	}
	public synchronized int getLastMessageId() {
		return lastMessageId;
	}
	public synchronized void setLastMessageId(int lastMessageId) {
		this.lastMessageId = lastMessageId;
		this.lastMessageTime = Calendar.getInstance().getTimeInMillis();
	}
	
	
	public boolean isServerAlive(){
		long delay = Calendar.getInstance().getTimeInMillis() - this.lastMessageTime;
		if(delay < Constants.SERV_TIMEOUT) return true;
		return false;
	}
	
	
	

}
